import sys
from PyQt5.QtWidgets import QApplication, QWidget, QDialog
from PyQt5.QtGui import QPalette
from PyQt5.QtCore import Qt, pyqtSlot
from day1.Dialog import Ui_Dialog


class MyDialog(QDialog):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.UnderLine.clicked.connect(self.underline_clicked)
        self.ui.Italic.clicked.connect(self.italic_clicked)
        self.ui.Bold.clicked.connect(self.bold_clicked)
        self.ui.Black.clicked.connect(self.set_color)
        self.ui.Red.clicked.connect(self.set_color)
        self.ui.Blue.clicked.connect(self.set_color)
        self.ui.ClearButton.clicked.connect(self.clear_clicked)

    def underline_clicked(self):
        clicked = self.ui.UnderLine.isChecked()
        font = self.ui.textEdit.font()
        font.setUnderline(clicked)
        self.ui.textEdit.setFont(font)

    def italic_clicked(self):
        clicked = self.ui.Italic.isChecked()
        font = self.ui.textEdit.font()
        font.setItalic(clicked)
        self.ui.textEdit.setFont(font)

    def bold_clicked(self):
        clicked = self.ui.Bold.isChecked()
        font = self.ui.textEdit.font()
        font.setBold(clicked)
        self.ui.textEdit.setFont(font)

    def set_color(self):
        palette = self.ui.textEdit.palette()
        if (self.ui.Black.isChecked()):
            palette.setColor(QPalette.Text,Qt.black)
        elif (self.ui.Red.isChecked()):
            palette.setColor(QPalette.Text, Qt.red)
        elif (self.ui.Blue.isChecked()):
            palette.setColor(QPalette.Text, Qt.blue)
        self.ui.textEdit.setPalette(palette)

    def clear_clicked(self):
        self.ui.textEdit.clear()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    my_dialog = MyDialog()
    my_dialog.show()
    sys.exit(app.exec_())
